package com.xbdx.lyboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
public class LoginController {

    //restful风格get请求进login页面
    @GetMapping("/login")
    public String login(){
        return "login";
    }

    //接收请求处理姓名和密码对应将姓名放入session中给后面拦截器使用
    @PostMapping("/login")
    public String login(HttpServletRequest request,
                        HttpSession session){

        String uname = request.getParameter("username");
        String password = request.getParameter("password");

        if (uname.equals("liyong") && password.equals("123456")) {

            session.setAttribute("user",uname);
            return "redirect:/";
        }else {
            return "redirect:/login";
        }


    }

}
